<?php
class M_nganh extends CI_Model{
	public function __construct()
	{
		parent::__construct();
		// Your own constructor code
	}
	
	public function get_nganh(){
		$this->db->select('*');
        $this->db->from('nganh');
        $this->db->where('state',1);
		//$this->db->order_by('POS','asc');
        $result = $this->db->get();
        return $result;        
        $result->free_result(); 
	}

	public function get_mon_CNTT($ma_nganh){
       	$this->db->select('*');
        $this->db->from('nganh');
		$this->db->join('mon','nganh.ma_nganh = mon.ma_nganh');
		$this->db->where('mon.ma_nganh','CNTT');
        $result = $this->db->get();
        return $result;        
        $result->free_result();
	}
    	public function get_mon_QT($ma_nganh){
       	$this->db->select('*');
        $this->db->from('nganh');
		$this->db->join('mon','nganh.ma_nganh = mon.ma_nganh');
		$this->db->where('mon.ma_nganh','QT');
        $result = $this->db->get();
        return $result;        
        $result->free_result();
	}
    	public function get_mon_TC($ma_nganh){
       	$this->db->select('*');
        $this->db->from('nganh');
		$this->db->join('mon','nganh.ma_nganh = mon.ma_nganh');
		$this->db->where('mon.ma_nganh','TC');
        $result = $this->db->get();
        return $result;        
        $result->free_result();
	}
      	public function get_mon_KT($ma_nganh){
       	$this->db->select('*');
        $this->db->from('nganh');
		$this->db->join('mon','nganh.ma_nganh = mon.ma_nganh');
		$this->db->where('mon.ma_nganh','KT');
        $result = $this->db->get();
        return $result;        
        $result->free_result();
	}
       	public function get_mon_TA($ma_nganh){
       	$this->db->select('*');
        $this->db->from('nganh');
		$this->db->join('mon','nganh.ma_nganh = mon.ma_nganh');
		$this->db->where('mon.ma_nganh','TA');
        $result = $this->db->get();
        return $result;        
        $result->free_result();
	}
       	public function get_mon_XD($ma_nganh){
       	$this->db->select('*');
        $this->db->from('nganh');
		$this->db->join('mon','nganh.ma_nganh = mon.ma_nganh');
		$this->db->where('mon.ma_nganh','XD');
        $result = $this->db->get();
        return $result;        
        $result->free_result();
	}
	public function get_mon($id){
		$this->db->select('*');
        $this->db->from('nganh');
		$this->db->join('mon','nganh.id= mon.nganh');
		$this->db->where('mon.nganh',$id);
        $result = $this->db->get();
        return $result;        
        $result->free_result(); 
	}

	function get_total_sub(){		
		return $this->db->count_all_results('mon');
	}
}
?>
